package cn.mrcode.mrweb.service;

import cn.mrcode.mrweb.model.Customer;
import cn.mrcode.smartFramework.annotation.Services;
import cn.mrcode.smartFramework.annotation.Transaction;
import cn.mrcode.smartFramework.helper.DataBaseHelper;
import cn.mrcode.smartFramework.utils.PropsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

/**
 * Created by zhuqiang on 2015/10/16 0016.
 */
@Services
public class CustomerService {
    private static final Logger LOGGER = LoggerFactory.getLogger(PropsUtil.class);

    // 获取客户列表
    public List<Customer> getCustomerList(){
        String sql = "SELECT * FROM customer";
        return DataBaseHelper.queryEntityList(Customer.class, sql);
    }

    //获取客户
    public Customer getCustomer(long id){
        String sql = "SELECT * FROM customer c WHERE c.id = ?";
        return DataBaseHelper.queryEntity(Customer.class,sql,id);
    }


    public boolean updateCustomer(long id,Map<String,Object> fieldMap){
        return DataBaseHelper.updateEntity(Customer.class,id,fieldMap);
    }

    //新增客户
    @Transaction
    public boolean createCustomer(Map<String,Object> fieldMap){
        return DataBaseHelper.insertEntity(Customer.class,fieldMap);
    }

    //删除客户
    public boolean deleteCustomer(long id){
        return DataBaseHelper.deleteEntity(Customer.class,id);
    }
}
